package chances.wechat.ctrl;


import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import chances.epg.commons.log.EpgLogFactory;
import chances.wechat.service.GatewayService;


@Controller
@RequestMapping(path="/wechat")
public class WGController {

	final static Logger sysLogger = EpgLogFactory.getSystemLogger();
	
	@Autowired
	private GatewayService gatewayService;
	
	
	/**
	 * 绑定用户机顶盒
	 * @param model
	 * @param request
	 * @param response
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping("/bind/device")
	public void bind(HttpServletRequest request,HttpServletResponse response) throws IOException {
		
		gatewayService.proxy(request, response, "/bind/device");
	}

	@RequestMapping("/bind/unbind")
	public void unbind(HttpServletRequest request,HttpServletResponse response) throws IOException{

		gatewayService.proxy(request, response, "/bind/unbind");
	}
	
	/**
	 * 查询用户绑定关系
	 * @param request
	 * @param response
	 * @throws IOException 
	 */
	@RequestMapping(path = "/bind/list")
	public void listBind(HttpServletRequest request,HttpServletResponse response) throws IOException{
		
		gatewayService.proxy(request, response, "/bind/list");
	}
	
	/**
	 * 修改盒子备注
	 * @param request
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping(path = "/bind/desc")
    public void descBind(HttpServletRequest request,HttpServletResponse response) throws IOException{    
        gatewayService.proxy(request, response, "/bind/desc");
    }
	
	/**
	 * 用户信息
	 * @param request
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping(path = "/bind/user")
    public void userBind(HttpServletRequest request,HttpServletResponse response) throws IOException{    
        gatewayService.proxy(request, response, "/bind/user");
    }
	
	/**
     * 设置默认盒子
     * @param request
     * @param response
     * @throws IOException
     */
    @RequestMapping(path = "/bind/master")
    public void masterBind(HttpServletRequest request,HttpServletResponse response) throws IOException{    
        gatewayService.proxy(request, response, "/bind/master");
    }
	
	/**
	 * 查询盒子是否在线
	 * @param stbNo
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(path = "/play/status")
	public void boxStatus(HttpServletRequest request,HttpServletResponse response) throws IOException {
		
		gatewayService.proxy(request, response, "/play/status");
	}
	
	/**
	 * 发送遥控指令
	 * @param userId
	 * @param stbNo
	 * @param playCtrlCmd
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(path = "/play/program")
	public void playProgram(HttpServletRequest request,HttpServletResponse response) throws IOException{
		gatewayService.proxy(request, response, "/play/program");
	}
	
	/**
	 * 发送播放指令
	 * @param userId
	 * @param stbNo
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(path = "/play/playctrl")
	public void playctrl(HttpServletRequest request,HttpServletResponse response) throws IOException{
		
		gatewayService.proxy(request, response, "/play/playctrl");
		
	}
	
	/**
	 * 查询播放历史记录
	 * @param userId
	 * @param size
	 * @param type
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(path = "/play/listRequest")
	public void listRequest(HttpServletRequest request,HttpServletResponse response) throws IOException{
		
		gatewayService.proxy(request, response, "/play/listRequest");
	}
	
	/**
	 * 删除播放历史记录
	 * @param userId
	 * @param codes
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(path = "/play/delReqs")
	public void delReqs(HttpServletRequest request,HttpServletResponse response) throws IOException{
		
		gatewayService.proxy(request, response, "/play/delReqs");
	}
	
	/**
	 * 上传照片
	 * @param userId
	 * @param mediaId
	 * @param nickName
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(path = "/photo/upload")
	public void photoUpload(HttpServletRequest request,HttpServletResponse response) throws IOException {
		String userId = request.getParameter("userId");
		String mediaId = request.getParameter("mediaId");
		String appCode = gatewayService.getAppCode();
		Map<String,String> map = new HashMap<String,String>();
		map.put("user_id",userId);
		map.put("media_id",mediaId);
		map.put("app_code",appCode);
		gatewayService.proxy(request, response, "/photo/download", map);
		
	}
	
	/**
	 * 查询照片
	 * @param userId
	 * @param pageSize
	 * @param pageIndex
	 * @param status
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(path = "/photo/list")
	public void photoList(HttpServletRequest request,HttpServletResponse response) throws IOException {
		
		gatewayService.proxy(request, response, "/photo/list");
	}
	
	/**
	 * 删除照片
	 * @param mediaIds
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(path = "/photo/dels")
	public void delPhotoes(HttpServletRequest request,HttpServletResponse response) throws IOException{
		
		gatewayService.proxy(request, response, "/photo/dels");
	}
	
	/**
	 * 删除照片
	 * @param mediaIds
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(path = "/photo/remove")
	public void removePhoto(HttpServletRequest request,HttpServletResponse response) throws IOException{
		
		gatewayService.proxy(request, response, "/photo/remove");
	}
	
	
	@RequestMapping(value = "/applet/uploadPhoto", method = RequestMethod.POST)
	public void uploadPhoto(HttpServletRequest request,HttpServletResponse response) throws IOException{
		
		gatewayService.proxyMultipart(request, response, "/applet/uploadPhoto");
	}
	
}
